Appendix 2B: OpenBUGS code for the multi-year unconstrained N-mixture model

This model is similar to the CMR model but with no distinction between intial "captures" and "recaptures".
It was used to obtain unconstrained estimates of N for each transect in each of the three years sampled.
It was also used to obtain estimates from the 2021 data only for comparison with CMR estimates.
This involved adjusting the model so that only the 2021 data were sampled (see below).

Initial values: these need to be at or above the minimum number on each transect each year
They needed to be adusted further for posterior predictions; I first set them at the median values
from the output, then changed all the zeros to ones
list(N=c(50,79,89,36,50,22,16,1,29,28,5,6,1,2,1,70,95,139,31,36,34,8,5,51,29,8,1,2,6,1,70,73,69,39,19,46,1,2,15,52,22,3,1,1,3))

Model {

	# Detection model
	a.p ~ dnorm(0,1)			# intercept of logit of detection probability (p)
	s.j.p ~ dunif(0,1)			# standard deviation among surveys in logit p
	tau.j.p <- pow(s.j.p,-2)	# convert to precision

	for (j in 1:n.surveys.max) {		# for each survey...
		re.j.p[j] ~ dnorm(0, tau.j.p)		# assign nightly random effect on detection prob.
		logit(p[j]) <- a.p+re.j.p[j]			# calc. prob of individual frog being detected
	}

	# Abundance model
	for (i in 1:n.rows) {	# for each transect for each year... 
	  
		a.N[i] ~ dnorm(0,0.1)		# prior for expected value of log(N)
		log(mu[i]) <- a.N[i]			# convert to untransformed N
		N[i] ~ dpois(mu[i])			# sample actual of N from expected value for N				
		}

	for (i in 1:n.rows) {	# for each transect for each year... 
		for (j in 1:n.surveys[i]) {		# for each sampling occasion
			n[i,j] ~ dbin(p[j],N[i])		# sample number frogs found from number present
			n.new[i,j] ~ dbin(p[j],N[i])		# for posterior predictive check	
		}

	}
}
